package com.glsc.ngateway.platform.repo;

import com.glsc.ngateway.platform.domain.FortressNew;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FortressNewRepository extends JpaRepository<FortressNew, Integer>, JpaSpecificationExecutor<FortressNew> {

    @Modifying
    @Query(value = "truncate table t_gw_fortress_new",nativeQuery = true)
    void trancateTable();

    @Query(value = "select m from FortressNew m where 1=1 " +
            "and (:#{#paramSearchDto.account} is null OR m.account LIKE CONCAT('%', :#{#paramSearchDto.account},'%') ) " +
            "and (:#{#paramSearchDto.name} is null OR m.name LIKE CONCAT('%', :#{#paramSearchDto.name},'%') ) " +
            "and (:#{#paramSearchDto.status} is null OR m.status LIKE CONCAT('%', :#{#paramSearchDto.status} ,'%') ) " +
            "and (:#{#paramSearchDto.position} is null OR m.position LIKE CONCAT('%', :#{#paramSearchDto.position},'%') ) " +
            "and (:#{#paramSearchDto.machine} is null OR m.machine LIKE CONCAT('%', :#{#paramSearchDto.machine},'%') ) " +
            "and (:#{#paramSearchDto.ip} is null OR m.ip LIKE CONCAT('%', :#{#paramSearchDto.ip},'%') ) " +
            "and (:#{#paramSearchDto.authFrom} is null OR m.authFrom LIKE CONCAT('%', :#{#paramSearchDto.authFrom},'%') ) " +
            "and (:#{#paramSearchDto.fromName} is null OR m.fromName LIKE CONCAT('%', :#{#paramSearchDto.fromName},'%') ) " +
            "and (:#{#paramSearchDto.departmentOne} is null OR m.departmentOne LIKE CONCAT('%', :#{#paramSearchDto.departmentOne},'%') ) " +
            "and (:#{#paramSearchDto.departmentOneId} is null OR m.departmentOneId = :#{#paramSearchDto.departmentOneId} ) " +
            "and (:#{#paramSearchDto.departmentTwo} is null OR m.departmentTwo LIKE CONCAT('%', :#{#paramSearchDto.departmentTwo},'%') ) " +
            "and (:#{#paramSearchDto.departmentTwoId} is null OR m.departmentTwoId = :#{#paramSearchDto.departmentTwoId} ) " +
            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode LIKE CONCAT('%', :#{#paramSearchDto.systemCode},'%') ) " +
            "and (:#{#paramSearchDto.systemName} is null OR m.systemName LIKE CONCAT('%', :#{#paramSearchDto.systemName},'%') ) " +
            "and (:#{#paramSearchDto.notOa} is null OR m.notOa = :#{#paramSearchDto.notOa} ) " +
            "and (:#{#paramSearchDto.createTime} is null OR m.createTime = :#{#paramSearchDto.createTime} ) " +
            "and (:#{#paramSearchDto.remark} is null OR m.remark LIKE CONCAT('%', :#{#paramSearchDto.remark},'%') ) " +
            "and (:#{#paramSearchDto.notStatus} is null OR m.status != :#{#paramSearchDto.notStatus} ) " )
    Page<FortressNew> searchByParam(Pageable pageable, FortressNew paramSearchDto);

    List<FortressNew> findAllByNotOa(Integer notOa);

    List<FortressNew> findAllByStatusNot(String status);
}